@include('public.page_styles')
<link rel="stylesheet" href="{{ asset("/AdminLTE/bower_components/bootstrap-daterangepicker/daterangepicker.css") }}">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
@include('public.top')
  <!-- Left side column. contains the logo and sidebar -->
@include('public.sidebar')
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        {{ trans('message.coupon') }}
        <small>{{ trans('message.edit') }}</small>
      </h1>
      <ol class="breadcrumb">
        <li><a ><i class="fa fa-dashboard"></i> {{ trans('message.home') }}</a></li>
        <li><a href="{{ url('coupon/list') }}">{{ trans('message.coupon') }}{{ trans('message.list') }}</a></li>
        <li class="active">{{ trans('message.coupon') }}{{ trans('message.edit') }}</li>
      </ol>
    </section>
    <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-md-12">
          <!-- Horizontal Form -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title">{{ trans('message.edit') }}</h3>
              <div class="box-tools">
                <div class="btn-group pull-right" style="margin-right: 10px">
                  <a href="{{ url('coupon/list') }}" class="btn btn-sm btn-default"><i class="fa fa-list"></i>&nbsp;{{ trans('message.list') }}</a>
                </div>
                <div class="btn-group pull-right" style="margin-right: 10px">
                  <a class="btn btn-sm btn-default form-history-back" onclick="goBack()"><i class="fa fa-arrow-left"></i>&nbsp;{{ trans('message.history-back') }}</a>
                </div>
              </div>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form name="editForm"  action="{{ url('coupon/'.$couponInfo->id) }}" method="post"  class="form-horizontal" onSubmit="return confirm();">
              <input type="hidden" name="_token"   value="{{ csrf_token() }}"/>
              <input type="hidden" name="id"   value="{{ $couponInfo->id }}"/>

              <div class="box-body">
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-2 control-label">所属网点</label>
                  <div class="col-sm-8">
                    <select class="form-control" name="bank_show_id">
                      <option value="0" >全部通用</option>
                      @if($bankShop)
                        @foreach($bankShop as $value)
                          <option value="{{ $value->id }}" @if($value->id == $couponInfo->bank_show_id) selected @endif>{{ $value->shopName }}</option>
                        @endforeach
                      @endif
                    </select>
                  </div>
                </div>

                  <div class="form-group">
                      <label for="activity_id" class="col-sm-2 control-label">可选择活动</label>
                      <div class="col-sm-8">
                          <select class="form-control" name="activity_id" required autofocus>
                              <option value="" selected>请选择...</option>
                              @if($activityS)
                                  @foreach($activityS as $value)
                                      <option value="{{ $value->id }}" @if($value->id == $couponInfo->activity_id) selected @endif>{{ $value->activity_name }}</option>
                                  @endforeach
                              @endif
                          </select>
                      </div>
                  </div>

                <div class="form-group {!! !$errors->has('name') ?: 'has-error' !!}">
                  <label for="name" class="col-sm-2 control-label">优惠券名称</label>
                  <div class="col-sm-8">
                    <span class="form-control-require">*</span>
                    <input type="text" class="form-control" id="name" name="name" placeholder="优惠券名称" value="{{ $couponInfo->name }}"   required autofocus>
                    @if($errors->has('name'))
                      @foreach($errors->get('name') as $message)
                        <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i>{{$message}}</label></br>
                      @endforeach
                    @endif
                  </div>
                </div>

                <div class="form-group {!! !$errors->has('cType') ?: 'has-error' !!}">
                  <label for="cType" class="col-sm-2 control-label">优惠券类型</label>
                  <div class="col-sm-8">
                    <span class="form-control-require">*</span>
                    <select class="form-control" name="cType" id="cType">
                        @if($CouponType)
                            @foreach($CouponType as $key=>$coupon)
                                <option value="{{ $coupon->state }}" @if($couponInfo->cType == $coupon->state ) selected @endif>{{ $coupon->stateName }}</option>
                            @endforeach
                        @endif
                    </select>
                    @if($errors->has('cType'))
                      @foreach($errors->get('cType') as $message)
                        <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i>{{$message}}</label></br>
                      @endforeach
                    @endif
                  </div>
                </div>

                <div class="form-group {!! !$errors->has('mixMoney') ?: 'has-error' !!}" id="mixMoneyDiv">
                  <label for="mixMoney" class="col-sm-2 control-label">最低使用金额</label>
                  <div class="col-sm-8">
                    <input type="text" class="form-control" id="mixMoney" name="mixMoney" placeholder="最低使用金额" value="{{ $couponInfo->mixMoney }}"    onkeyup= "if( ! /\d+(\.\d{1,2})?/.test(this.value)){alert('只能输入数字，小数点后只能保留两位');this.value='';}">
                    @if($errors->has('mixMoney'))
                      @foreach($errors->get('mixMoney') as $message)
                        <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i>{{$message}}</label></br>
                      @endforeach
                    @endif
                  </div>
                </div>

                <div class="form-group {!! !$errors->has('money') ?: 'has-error' !!}" id="moneyDiv">
                  <label for="money" class="col-sm-2 control-label">抵扣金额</label>
                  <div class="col-sm-8">
                    <input type="text" class="form-control" id="money" name="money" placeholder="抵扣金额" value="{{ $couponInfo->money }}"   autofocus onkeyup= "if( ! /\d+(\.\d{1,2})?/.test(this.value)){alert('只能输入数字，小数点后只能保留两位');this.value='';}">
                    @if($errors->has('money'))
                      @foreach($errors->get('money') as $message)
                        <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i>{{$message}}</label></br>
                      @endforeach
                    @endif
                  </div>
                </div>

                <div class="form-group {!! !$errors->has('discount') ?: 'has-error' !!}" id="discountDiv" >
                  <label for="discount" class="col-sm-2 control-label">折扣值</label>
                  <div class="col-sm-8">
                    <input type="text" class="form-control" id="discount" name="discount" placeholder="95" value="{{ $couponInfo->discount }}"   autofocus onkeyup= "if(! /^[0-9]{1,2}$/.test(this.value)){alert('只能输入两位数字');this.value='';}" >
                    @if($errors->has('discount'))
                      @foreach($errors->get('discount') as $message)
                        <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i>{{$message}}</label></br>
                      @endforeach
                    @endif
                  </div>
                </div>

                <div class="form-group {!! !$errors->has('cDesc') ?: 'has-error' !!}">
                  <label for="cDesc" class="col-sm-2 control-label">优惠券描述</label>
                  <div class="col-sm-8">
                    <input type="text" class="form-control" id="cDesc" name="cDesc" placeholder="描述" value="{{ $couponInfo->cDesc }}"  >
                    @if($errors->has('cDesc'))
                      @foreach($errors->get('cDesc') as $message)
                        <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i>{{$message}}</label></br>
                      @endforeach
                    @endif
                  </div>
                </div>

                <div class="form-group {!! !$errors->has('validity') ?: 'has-error' !!}">
                  <label for="validity" class="col-sm-2 control-label">使用有效期</label>
                  <div class="col-sm-5">
                    <div id="reportrange" class="dateRange" >
                      <input type="text" class="form-control " id="searchDateRange" name="validity" value="@if($couponInfo->startTime) {{ $couponInfo->startTime }} - {{ $couponInfo->endTime }} @else {{ $couponInfo->validity }} @endif" placeholder="输入月份 / 日期">
                    </div>
                      @if($errors->has('validity'))
                          @foreach($errors->get('validity') as $message)
                              <label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i>{{$message}}</label></br>
                          @endforeach
                      @endif
                  </div>
                    <span style="line-height: 34px;font-size: 10px;">例如：2017-09-26 00:00:00 - 2017-10-08 23:00:00 或者 月份值（1）</span>
                </div>

              <div class="form-group">
                  <label for="remark" class="col-sm-2 control-label">备注</label>
                  <div class="col-sm-8">
                      <input type="text" class="form-control" id="remark" name="remark" placeholder="" value="{{ $couponInfo->remark }}"  >
                  </div>
              </div>

              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                <div class="col-sm-2">
                </div>
                <div class="col-sm-8">
                  <div class="btn-group pull-right">
                    <button type="button" class="btn btn-info pull-right btn-js-form-submit" >提交</button>
                  </div>
                  <div class="btn-group pull-left">
                    <button type="reset" class="btn btn-warning">撤销</button>
                  </div>
                </div>
              </div>
              <!-- /.box-footer -->
            </form>
          </div>
          <!-- /.box -->
        </div>
        <!--/.col (right) -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
@include('public.bottom')

  <!-- Control Sidebar -->
{{--@include('public.aside')--}}
  <!-- /.control-sidebar -->
  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

@include('public.javascript')
{{--<script src="{{ asset ("/AdminLTE/bower_components/fastclick/lib/fastclick.js") }}" type="text/javascript"></script>--}}
<script src="{{ asset ("/AdminLTE/bower_components/moment/min/moment.min.js") }}" type="text/javascript"></script>
<script src="{{ asset ("/AdminLTE/bower_components/bootstrap-daterangepicker/daterangepicker.js") }}" type="text/javascript"></script>

<script type="text/javascript">
    $(function(){
//        $('#reportrange input').val(moment().subtract('hours', 1).format('YYYY-MM-DD HH:mm:ss') + ' - ' + moment().format('YYYY-MM-DD HH:mm:ss'));
        $('#reportrange').daterangepicker({
            showDropdowns : true,
            showWeekNumbers : false, //是否显示第几周
//            timePicker : true, //是否显示小时和分钟
//            timePickerIncrement : 60, //时间的增量，单位为分钟
//            timePicker12Hour : false, //是否使用12小时制来显示时间
//            opens : 'right', //日期选择框的弹出位置
            buttonClasses : [ 'btn btn-default' ],
            applyClass : 'btn-small btn-primary blue',
            cancelClass : 'btn-small',
            format : 'YYYY-MM-DD HH:mm:ss', //控件中from和to 显示的日期格式
            separator : ' to ',
            locale : {
                applyLabel : '确定',
                cancelLabel : '取消',
                fromLabel : '起始时间',
                toLabel : '结束时间',
                customRangeLabel : '自定义',
                daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
                monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
                    '七月', '八月', '九月', '十月', '十一月', '十二月' ],
                firstDay : 1
            }
        }, function(start, end, label) {//格式化日期显示框

            $('#reportrange input').val(start.format('YYYY-MM-DD HH:mm:ss') + ' - ' + end.format('YYYY-MM-DD HH:mm:ss'));
        });

    });


    jQuery(function ($) {
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': '{{ csrf_token() }}'
            }
        });


    @if(session()->has('fail'))
      alertMess("{{session()->get('fail')}}");
    @endif

  });

    var cType=$('#cType').find('option:selected').val();
    if(cType == 1 || cType == 3 || cType == 4){
        $('#discountDiv').hide();
        $('#discountDiv').find('input').removeAttr("required");
        $('#discountDiv').find('input').val('');
        $('#moneyDiv').show();
        $('#moneyDiv').find("input").attr("required", "true");
        $('#mixMoneyDiv').show();

    }else{
        $('#moneyDiv').hide();
        $('#moneyDiv').find("input").removeAttr("required");
        $('#moneyDiv').find("input").val('');
        $('#mixMoneyDiv').hide();
        $('#discountDiv').show();
        $('#discountDiv').find('input').attr("required", "true");
    }

    $("#cType").change(function(){
        var checkValue = $(this).find('option:selected').val();
        if(checkValue =='1' || checkValue =='3' || checkValue =='4'){
            $('#discountDiv').hide();
            $('#discountDiv').find('input').removeAttr("required");
            $('#discountDiv').find('input').val('');
            $('#moneyDiv').show();
            $('#moneyDiv').find("input").attr("required", "true");
            $('#mixMoneyDiv').show();
        }else{
            $('#moneyDiv').hide();
            $('#moneyDiv').find("input").removeAttr("required");
            $('#moneyDiv').find("input").val('');
            $('#mixMoneyDiv').hide();
            $('#discountDiv').show();
            $('#discountDiv').find('input').attr("required", "true");
        }
    });


    function confirm() {
        var validity = $("input[name='validity']").val();
        if(validity.length == 0) {
            alert("有效期不能为空");
            $("#searchDateRange").focus();
            return false;
        } else  if(validity.indexOf(' - ') == -1 && isNaN(validity) ){
            alert('必须填写数字或者日期区间');
            $("#searchDateRange").focus();
            return false;
        }else {
            return true;
        }
    }

    var _ajaxSubmitSending = false;
    $(".btn-js-form-submit").click(function (e) {
        if (_ajaxSubmitSending) {
            return;
        } else {
            _ajaxSubmitSending = true;
            _loadingFuc();
        }

        $('form[name="editForm"]').submit();
        _ajaxSubmitSending = false;
        setTimeout(function(){
            $.unblockUI();
        }, 1500);
    });




</script>



</body>
</html>
